package com.wanxi.servlet.view;

import com.wanxi.model.*;
import com.wanxi.service.*;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        2.得到前端的值

//        3.封装数据到model

//        4.处理逻辑关系
        CompanyService companyService = new CompanyService();
        NavService navService = new NavService();
        NewsService newsService=new NewsService();
        ProductService productService=new ProductService();
//        5.得到逻辑处理后的返回值

//        公司信息
        CompanyModel companyModel = companyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);
//        导航信息
        List<NavModel> navModelList = navService.getNavModelList();
        req.setAttribute("navModelList", navModelList);
//        新闻信息
        List<NewsModel> newsModelList=newsService.getNewsModelList();
        req.setAttribute("newsModelList", newsModelList);
//        产品信息
        List<ProductModel> productModelList=productService.getProductModelList();
        req.setAttribute("productModelList", productModelList);
//        6.转发数据

        req.getRequestDispatcher("/jsp/index.jsp").forward(req, resp);
    }
}
